package com.winway.sixbook.ui;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.winway.sixbook.R;
import com.winway.sixbook.service.DataBaseManagementHelper;
import com.winway.sixbook.service.RecordDataManager;

import android.app.ExpandableListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SimpleExpandableListAdapter;

public class NewTodayListActivity extends ExpandableListActivity {
	
	private static final String TAG = "NewTodayListActivity";
	RecordDataManager recordDataManager ;
	DataBaseManagementHelper dataBaseManagementHelper;
	private Button record_btn_xinzeng =null;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_today_list);
        
        record_btn_xinzeng = (Button)findViewById(R.id.record_btn_xinzeng);
        
        if (recordDataManager == null) {
        	recordDataManager = new RecordDataManager(this);
        	recordDataManager.openDataBase();
        }

        String[] str={"时间一","时间二","时间三","时间四","时间五","时间六","最好"};
        List<Map<String,Object>> Groups = new ArrayList<Map<String,Object>>();
        for(int i=0;i<str.length;i++){
        	Map<String,Object> group = new HashMap<String,Object>();
        	group.put("groupname", str[i]);
        	Groups.add(group);
        }
        
        List<List<Map<String,Object>>> Childs = new ArrayList<List<Map<String,Object>>>();

        for (int j=1;j<=str.length;j++){
        	List<Map<String,Object>> child = new ArrayList<Map<String,Object>>(); 
        	Cursor cursor = recordDataManager.findRecordByTimeslot("","",""+j);
            if(cursor != null ){
               if( cursor.moveToFirst() ){
                   do{
   			        	Map<String,Object> child1date = new HashMap<String,Object>();
   			        	child1date.put("Content", cursor.getString(2));
   			        	child1date.put("Userid", cursor.getString(1));
   			        	child1date.put("Typeid", cursor.getString(3));
   			        	child1date.put("Typename", cursor.getString(4));
   			        	child1date.put("Addtime", cursor.getString(5));
   			        	child1date.put("Timeslot", cursor.getString(6));
   			        	Log.v(TAG, cursor.getString(0) +"===" +cursor.getString(1)+"===" +cursor.getString(2)+"===" +cursor.getString(3)+"===" +cursor.getString(4));
   			        	child.add(child1date);
                   }while( cursor.moveToNext());
               }
            }
            cursor.close();
	        Childs.add(child);
        }
        SimpleExpandableListAdapter simpleExpandListAdapter = new SimpleExpandableListAdapter(NewTodayListActivity.this, 
        		Groups, R.layout.group, new String[]{"groupname"},new int[]{R.id.group},
        		Childs, R.layout.child, new String[]{"Content","Typename"},new int[]{R.id.record_content,R.id.record_typename});
        setListAdapter(simpleExpandListAdapter);
        
        //设置新增按钮监听事件
        record_btn_xinzeng.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Log.v(TAG, ""+v.getId());
			}
		});
    }
    

}